package com.dy.service;

import com.dy.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * @Auther: dy
 * @Date: 2022/4/24 - 04 - 24 - 22:53
 * @Description: com.dy.service
 * @version: 1.0
 */
@Service
public class Shakedown {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Qualifier("com.dy.service.IFeignOrderService")
    @Autowired
    private IFeignOrderService feignOrderService;
    @Qualifier("com.dy.service.IFeignCinemaService")
    @Autowired
    private IFeignCinemaService feignCinemaService;

    @Scheduled(cron = "0 25 9 * * ?")
    public void persistent(){
        Map<Object, Object> shakedown = redisTemplate.opsForHash().entries("shakedown");
        Collection<Object> values = shakedown.values();
        System.out.println(shakedown);
        Iterator<Object> iterator = values.iterator();
        if (iterator.hasNext()){
            Order order = (Order) iterator.next();
            System.out.println(order);
            if (feignOrderService.persistent(order)){
                feignCinemaService.getOrder(order);
            }
        }
    }

}
